﻿namespace block_explorer.NoiseSystem.Nodes
{
    class ScaleDomain : INode
    {
        INode mSource;
        INode mScaleX;
        INode mScaleY;
        INode mScaleZ;

        public ScaleDomain(INode source, INode sX, INode sY, INode sZ)
        {
            mSource = source;
            mScaleX = sX;
            mScaleY = sY;
            mScaleZ = sZ;

            if (mScaleX == null)
                mScaleX = new Constant(1.0);
            if (mScaleY == null)
                mScaleY = new Constant(1.0);
            if (mScaleZ == null)
                mScaleZ = new Constant(1.0);
        }

        public ScaleDomain(INode source, double sX, double sY, double sZ)
        {
            mSource = source;
            mScaleX = new Constant(sX);
            mScaleY = new Constant(sY);
            mScaleZ = new Constant(sZ);
        }

        public double Value(double x, double y, double z)
        {
            return mSource.Value(x * mScaleX.Value(x, y, z), y * mScaleY.Value(x, y, z), z * mScaleZ.Value(x, y, z));
        }
    }
}
